﻿Imports HMSLibrary
Imports HMSDataLayer
Imports System.Collections.ObjectModel

Public Class PatientDiagnosisWindow

    Public Property DiagnosisList As ObservableCollection(Of PatientDiagnosis)
    Dim lstCl As ObservableCollection(Of Diagnosis)
    Private Sub MasterWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        DiagnosisList = New ObservableCollection(Of PatientDiagnosis)()
        Dim dataProvider As New MasterDataLayer()
        lstCl = dataProvider.GetDiagnosisList()
        DiagnosisTreeView.ItemsSource = lstCl
        DiagnosisDataGrid.ItemsSource = lstCl
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Private Sub DiagnosisTreeRadioButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles DiagnosisTreeRadioButton.Click, DiagnosisListRadioButton.Click
        If DiagnosisListRadioButton.IsChecked Then
            DiagnosisDataGrid.Visibility = Visibility.Visible
            DiagnosisTreeView.Visibility = Visibility.Collapsed
        Else
            DiagnosisDataGrid.Visibility = Visibility.Collapsed
            DiagnosisTreeView.Visibility = Visibility.Visible
        End If
    End Sub

    Private Sub AddDiagnosisButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles AddDiagnosisButton.Click
        AddDiagnosisItems(lstCl)
        Me.Close()
    End Sub

    Private Sub AddDiagnosis(ByVal sender As Diagnosis)
        If sender.Checked = True Then
            Dim dia As New PatientDiagnosis
            dia.Name = sender.Name
            dia.ID = sender.ID
            dia.diagnosisDateTime = Date.Now
            DiagnosisList.Add(dia)
        End If
    End Sub

    Private Sub AddDiagnosisItems(ByVal sender As ObservableCollection(Of Diagnosis))
        For Each d In sender
            AddDiagnosis(d)
            If d.subItems.Count > 0 Then
                AddDiagnosisItems(d.subItems)
            End If
        Next
    End Sub
End Class
